/********************************************************
Code to create the predicted probabilities for Figure 2
using the Pew CNN Data. Also creates the Table for these reults. 
Plotting is done using R. 
***********************************************************/

/**************************
		Data
**************************/

clear
*change directory to "....\Data\"
*cd 
*loads the data
use "pew_cnn_comb.dta"

/**************************
		Cleaning
Some of the labels are not right in the data file due to recoding in R; this fixes them
**************************/

**Income
label def inc1 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000-99,999" 5 "100,000+"
label values income1 inc1
label var income1 "Income"

label def inc2 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000+"
label values income2 inc2
label var income2 "Income"

**Gender
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

**Education 
label var educ "Education"
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "Post-BA"
label values educ edu

**Race/Ethnicity
*Remove the 9
recode race_eth (9 = .)
label var race_eth "Race/Ethnicity"
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Other Race"
label values race_eth rac

**Age
label var age "Age"

**Sponsor
encode sponsor, gen(sponsor1)

**Year
label var year "Year of Survey"

**Too Extreme
label var too_extreme1 "Parties Too Extreme?"
label def too1 1 "Neither" 2 "One Too Extreme" 3 "Both Too Extreme"
label values too_extreme1  too1

***PID & Ideol Ext
label var pid_ext "PID Extremity"
label def pext 1 "Independent" 2 "Leaner" 3 "Partisan"
label values pid_ext pext

label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Liberal/Conservative" 3 "Very Liberal/Conservative"
label values ideol_ext iext


/**************************
	Model and Predictions
**************************/

****Without Controls
eststo clear
eststo: gsem (i.too_extreme1 <- i.ideol_ext##c.year S[surveyid]@1) [pweight=weight], mlogit
	
	forval i = 1/3 {
		margins, dydx(year) by(ideol_ext) predict(outcome(`i'.too_extreme1)) saving(probs_`i'_nocontrol, replace)
	}	
	
esttab using "table_oa3.rtf", replace onecell se aic bic label nobaselevels unstack b(3) ///
	mtitles("Neither" "One Party" "Both Parties") ///
	title("{\b Table OA3:} Ideology x Year Interaction (Pew/CNN Data)")


